package CreatePhase;


import Entities.Brick;
import Entities.Scene;
import java.awt.Point;


public class CollisionControl {
    private Scene scene;
    private Brick brick;
    private int resistance;

    public CollisionControl(Scene scene, int resistance) {
        this.scene = scene;
        brick = new Brick();
        this.resistance = resistance;
    }

    public boolean collision(Point point) {
        brick.setX(point.x);
        brick.setY(point.y);
        if(resistance < 0 || resistance > 4)  return true;
        brick.setResistance(resistance);
        for(int i = 0; i < scene.getNumElems(); i++){
            Brick auxBrick;
            auxBrick = (Brick) scene.getChild(i);
            if(Math.abs(auxBrick.getX()-brick.getX()) <= brick.getWidth()){
                if(Math.abs(auxBrick.getY()-brick.getY()) <= brick.getHeight()) return true;
            }
        }
        return false;
    }

    public Brick getBrick() {
        return brick;
    }
  
}
